home *** CD-ROM | disk | FTP | other *** search
- /* %filename% */
- /* Created %date% %time% by AppMaker */
-
- %If MPW%
- #include <Types.h>
- #include <Quickdraw.h>
- #include <Controls.h>
- #include <Dialogs.h>
- #include <Events.h>
- #include <Lists.h>
- #include <Menus.h>
- #include <TextEdit.h>
-
- %end if%
- #include "Globals.h"
- #include "ResourceDefs.h"
- #include "Dispatcher.h"
- #include "Miscellany.h"
- %UsesDialogs%
-
- #include "%unitname%.h"
-
- %If MPW%
- #include <Desk.h>
- #include <Packages.h>
- #include <ToolUtils.h>
-
- %end if%
- #define nil 0L
-
- #define dialogTop 75
- #define dialogLeft 85
-
- short numOpenTypes;
- SFTypeList openTypeList;
- %If MPW%
-
- #pragma segment %unitname%
- %end if%
-
- /*----------*/
- void Init%MenuName% ()
- {
- numOpenTypes = 1;
- openTypeList [0] = 'TEXT';
- } /*Init%MenuName%*/
-
- /*----------*/
- Boolean OkToOpen (fType)
- OSType fType;
- {
- short i;
- enum {searching, found, notFound}
- status;
-
- i = 0;
- status = searching;
- while (status == searching) {
- if (i >= numOpenTypes) {
- status = notFound;
- } else {
- if (fType == openTypeList [i]) {
- status = found;
- } else {
- i++;
- }
- }
- } /*while*/
- return (status == found);
- } /*OkToOpen*/
-
- /*----------*/
- Boolean OpenApplFile (short vRefNum,
- Str255 fName,
- short *fRefNum);
- Boolean OpenApplFile (vRefNum, fName, fRefNum)
- short vRefNum;
- Str255 fName;
- short *fRefNum;
- {
- Boolean okay;
-
- /* application-specific Open file */
- okay = CheckOS (FSOpen (fName, vRefNum, fRefNum));
- return (okay);
- } /*OpenApplFile*/
-
- /*----------*/
- void CloseApplFile (short fRefNum);
- void CloseApplFile (fRefNum)
- short fRefNum;
- {
- Boolean okay;
-
- /* application-specific Close file */
- if (cur->windowKind == 1) { /*1st or only window in set*/
- okay = CheckOS (FSClose (fRefNum));
- }
- } /*CloseApplFile*/
-
- /*----------*/
- void SaveApplFile (short fRefNum);
- void SaveApplFile (fRefNum)
- short fRefNum;
- {
- %if MPW%
- #pragma unused (fRefNum)
-
- %end if%
- /* application-specific Save file */
- cur->dirty = false;
- } /*SaveApplFile*/
-
- /*----------*/
- Boolean ReadApplFile (short fRefNum);
- Boolean ReadApplFile (fRefNum)
- short fRefNum;
- {
- %if MPW%
- #pragma unused (fRefNum)
-
- %end if%
- /* application-specific Read file */
- return (false);
- } /*ReadApplFile*/
-
- /*----------*/
- void DoNew (void);
- void DoNew ()
- {
- Str255 untitled;
-
- BlockMove (&(**GetString (UntitledID)), untitled, 256);
- OpenWindows (untitled, 0, 0);
- } /*DoNew*/
-
- /*----------*/
- void OpenFile (fileName, vRefNum)
- Str255 fileName;
- short vRefNum;
- {
- short fRefNum;
-
- if (OpenApplFile (vRefNum, fileName, &fRefNum)) {
- OpenWindows (fileName, vRefNum, fRefNum);
- }
- } /*OpenFile*/
-
- /*----------*/
- void DoOpen (void);
- void DoOpen ()
- {
- Point dialogOrigin;
- SFReply sfInfo;
-
- SetPt (&dialogOrigin, dialogLeft, dialogTop);
- SFGetFile (dialogOrigin, "", nil, numOpenTypes, &openTypeList, nil, &sfInfo);
- if (sfInfo.good) {
- OpenFile (sfInfo.fName, sfInfo.vRefNum);
- }
- } /*DoOpen*/
-
- /*----------*/
- void Open0Files ()
- {
- DoNew ();
- } /*Open0Files*/
-
- /*----------*/
- void DoSaveAs (void);
- void DoSaveAs ()
- {
- SFReply sfInfo;
- short fRefNum;
- StringHandle prompt;
- Str255 suggestion;
- StringHandle untitled;
-
- prompt = GetString (SaveAsPromptID);
- suggestion [0] = 0;
-
- if (CreateFile (&sfInfo, *prompt, suggestion, 'XXXX', 'TEXT')) {
- if (cur->fileNum != 0) {
- CloseApplFile (cur->fileNum);
- }
- if (OpenApplFile (sfInfo.vRefNum, sfInfo.fName, &fRefNum)) {
- SetWTitle (curWindow, sfInfo.fName);
- cur->fileNum = fRefNum;
- cur->volNum = sfInfo.vRefNum;
- SaveApplFile (cur->fileNum);
- } else { /*should never happen*/
- untitled = GetString (UntitledID);
- SetWTitle (curWindow, *untitled);
- cur->fileNum = 0;
- cur->volNum = 0;
- }
- }
- } /*DoSaveAs*/
-
- /*----------*/
- void DoSave (void);
- void DoSave ()
- {
- if (cur->fileNum == 0) {
- DoSaveAs ();
- } else {
- SaveApplFile (cur->fileNum);
- }
- } /*DoSave*/
-
- /*----------*/
- void CloseApplWindow (void);
- void CloseApplWindow ()
- {
- enum {saveItem = 1, cancelItem, discardItem};
-
- Str255 curTitle;
- short itemNum;
- Boolean okay;
-
- okay = true;
- SetInfo (FrontWindow ());
- if (cur->dirty) {
- GetWTitle (curWindow, curTitle);
- ParamText (curTitle, "", "", "");
- InitCursor ();
- itemNum = Alert (SaveID, nil);
- switch (itemNum) {
- case saveItem:
- DoSave ();
- okay = !errorFlag;
- break;
- case discardItem:
- /*Do nothing*/;
- break;
- case cancelItem:
- errorFlag = true;
- okay = false;
- break;
- } /*switch*/
- }
- if (okay) {
- if (cur->fileNum != 0) {
- CloseApplFile (cur->fileNum);
- }
- CloseCurWindow ();
- }
- } /*CloseApplWindow*/
-
- /*----------*/
- void DoClose ()
- {
- WindowPeek frontPeek;
-
- frontPeek = (WindowPeek) FrontWindow ();
- if (frontPeek->windowKind < 0) {
- CloseDeskAcc (frontPeek->windowKind);
- } else if (frontPeek->windowKind == dialogKind) {
- CloseModelessDialog (FrontWindow ());
- } else {
- CloseApplWindow ();
- }
- } /*DoClose*/
-
- /*----------*/
- void DoQuit (void);
- void DoQuit ()
- {
- Boolean quitting;
-
- quitting = true;
- while (quitting && (FrontWindow () != nil)) {
- SystemTask ();
- DoClose ();
- if (errorFlag) {
- quitting = false;
- }
- } /*while*/
-
- if (quitting) {
- quittingTime = true;
- }
- } /*DoQuit*/
-
- %DoMenuItems%
- /*----------*/
- void Do%MenuName% (itemNr)
- short itemNr;
- {
- errorFlag = false;
-
- switch (itemNr) {
- %HandleMenuItems%
- } /*switch*/
- } /*Do%MenuName%*/
-